package me.keiwu.log.controller.rpc;

import me.keiwu.log.service.LogDonateService;
import me.keiwu.pub.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by kei on 18/12/2017.
 */
@RestController
@RequestMapping("/rpc/log/donate")
public class DonateRpcController {


    @Autowired
    private LogDonateService logDonateService;


    @RequestMapping("/step")
    public void logDonateStep(Long userId, Integer donateStep, Integer logTime) {
        logDonateService.logDonateStep(userId, donateStep, logTime);
    }

    @RequestMapping("/repair")
    public void repair(String start) {
        Date startDate = DateUtil.parseDate(start, "yyyy-MM-dd HH:mm:ss");
        int from = DateUtil.getUnixTime(startDate);
        int to = DateUtil.getUnixTime(DateUtil.getDayEnd(new Date()));
        logDonateService.repairFromDB(from, to);
    }


}
